@extends("admin.base")
@section("contents")
    <div class="row mt-5">
        <div class="col-lg-6 m-auto mt-5">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <a href="addcountry"><button class="btn btn-outline-primary" style="border-radius: 10px;">添加信息</button></a>
                        <table class="table table-primary table-striped mb-0">
                            <tr>
                                <th>id</th>
                                <th>type_ch</th>
                                <th>type_uy</th>
                                <th>order</th>
                                <th>created_at</th>
                                <th>updated_at</th>
                                <th>操作</th>
                            </tr>
                            @foreach($countrys as $country)
                                <tr>
                                    <td>{{$country->id}}</td>
                                    <td>{{$country->country_ch}}</td>
                                    <td>{{$country->country_uy}}</td>
                                    <td>{{$country->order}}</td>
                                    <td>{{$country->created_at}}</td>
                                    <td>{{$country->updated_at}}</td>
                                    <td>
                                        <a href=updatecountry?id={{$country->id}}">
                                            <button class="btn btn-outline-primary">修改</button>
                                        </a>
                                        <button onclick="deletecountry({{$country->id}})" class="btn btn-outline-danger">删除
                                        </button>
                                    </td>
                                </tr>
                            @endforeach
                        </table>
                    </div>
                </div>
            </div>
        </div>
@endsection


@section("scripts")
    <script>
        function deletecountry(id){
            console.log(id)
            swal({
                title:"请确认操作",
                text:"数据被删除后无法恢复，请确认",
                icon:"warning",
                buttons:["取消","确认"],
            }).then((willDelete=>{
if (willDelete){
    $.ajax({
        url:"deletecountry",
        data:{"id":id},
        dataType:"json",
        type:"GET",
        async:true,
        headers:{'X-CSRF-TOKEN':'{{csrf_token()}}'},
        success:function (req){
            swal({
                title:"操作成功",
                text:req.title,
                icon:"success",
                button:"知道了",
            }),setTimeout(function (){
                location.reload();
            },1000)
        }
    });

}
            }));
        }
    </script>
@endsection
